//
//  LProtocolShowViewController.m
//  Learn
//
//  Created by zyl_macbookpro on 2024/4/9.
//  Copyright © 2024 迟建国. All rights reserved.
//

#import "LProtocolShowViewController.h"
#import "MineAPIManager.h"

@interface LProtocolShowViewController ()

@property(nonatomic ,strong)NSDictionary *data;

@property(nonatomic ,strong)UIScrollView *containView;

@property(nonatomic ,strong)UILabel *containLabel;

@property(nonatomic ,assign)int kind;

@end

@implementation LProtocolShowViewController
- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    self.navigationController.navigationBar.hidden = NO;
    [self renderNavBarWithBackgroundImage:[UIImage imageWithColor:lWhiteColor] backgroundColor:lClearColor shadowColor:nil textAttributeDic:@{NSForegroundColorAttributeName:rgba(51, 51, 51, 1),NSFontAttributeName:MFontWithSize(18)} enableScrollEdgeAppearance:NO];
}
- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    self.navigationController.navigationBar.hidden = YES;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self.view addSubview:self.containView];
    [self setBackButtonIsHidden:NO];
    self.view.backgroundColor = lWhiteColor;
    self.title = self.kind == 1?@"使用协议": self.kind == 2?@"隐私政策": self.kind == 3?@"儿童隐私保护政策":@"";
    [MineAPIManager GetAboutMsgWithParam:@{} result:^(NSDictionary * _Nonnull dic) {
        if (dic[@"data"]) {
            
            self.data = dic[@"data"];
            NSString *key = self.kind == 1?@"use_agreement": self.kind == 2?@"privacy_agreement": self.kind == 3?@"protect_agreement":@"";
            NSString *str = [NSString stringWithFormat:@"%@",self.data[key]];
            if (str.length > 0) {
                NSMutableAttributedString *attrStr = [[NSMutableAttributedString alloc] initWithData:[str dataUsingEncoding:NSUnicodeStringEncoding] options:@{NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType} documentAttributes:nil error:nil];
                self.containLabel.attributedText = attrStr;
                [self.containLabel sizeToFit];
                self.containView.contentSize = CGSizeMake(lScreenWidth, self.containLabel.bottom + 10);
            }
            
            
        }
    }];
  
}
- (UIScrollView *)containView
{
    if (!_containView) {
        _containView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, lTopBarHeight, lScreenWidth, lScreenHeight - lTopBarHeight - lBottomDangerousAreaHeight)];
        _containView.backgroundColor = lClearColor;
        _containView.showsVerticalScrollIndicator = NO;
        _containView.showsHorizontalScrollIndicator = NO;
        
        
        self.containLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 10, lScreenWidth - 20, CGFLOAT_MIN)];
        self.containLabel.font = MFontWithSize(16);
        self.containLabel.textColor = rgba(51, 51, 51, 1);
        self.containLabel.textAlignment = NSTextAlignmentLeft;
        [_containView addSubview:self.containLabel];
        
    }
    return _containView;
}
- (void)setParaObject:(NSObject *)paraObject
{
    NSNumber *num = (NSNumber *)paraObject;
    self.kind = num.intValue;
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
